<?php
/**
 * Ora - 后台 视频 管理模块
 * @author lan7
 * @copyright lan7.net
 * @version 2.0
 */

if(!defined('IN_ORA')) {
	exit('Access Denied');
}

class admin_vod extends mod{
	function admin_vod(){
		parent::__construct();
		session_start();
		$this->setTplDir(PUBLIC_PATH);
		$this->setMsgTpl("admin/msg.html");
		if(!isset($_SESSION[$GLOBALS['ora_cfg']['sess_prefix']."admin"])){
			$this->showMsg("请先登录!",parse_uri("common-login"),1);
		}
	}

	/**
	 * 新增视频
	 *
	 */
	function add(){
		$GLOBALS['tpl']->assign('page_title','新增视频');
		$GLOBALS['tpl']->display('admin/vod.html');
	}

	/**
	 * 保存视频
	 *
	 */
	function save(){
		$tit = clear_html($_POST['v_title']);
		import("lib.vod");
		$vod = vod_lib::getVodInf($_POST['url']);
		if($vod){
			if(!preg_match('/http:\/\//i',$vod['pic'])){
				import("lib.image");
				image::thumb(UPLOAD_PATH.$vod['pic'],'',180,135);
			}
			$sql = "insert into ".tn('vod')."(v_title,v_url,v_pic,v_swf,dateline) values(";
			$sql.= " '$tit','{$vod['url']}','{$vod['pic']}','{$vod['swf']}',".time().")";
			if($GLOBALS['db']->execute($sql,1)){
				$id = $GLOBALS['db']->getLastInsId();
				exit('{result:true,id:'.$id.',url:"'.$vod['url'].'",pic:"'.$vod['pic'].'",swf:"'.$vod['swf'].'",title:"'.$tit.'"}');
			}else{
				exit('{result:false}');
			}
		}
		exit('{result:false}');
	}
}
?>